﻿using System;
using System.Collections.Generic;

using Cookbook.Services.Core.Domain;

using Cooking.Services.Specs.Support;

namespace Cooking.Services.Specs.Builders
{
    public class RecipeBuilder : TestDataBuilder<Recipe>
    {
        private List<Ingredient> ingredients = new List<Ingredient>();

        /// <summary>
        /// Called to create an instance of <typeparamref name="TSubject"/>.
        /// </summary>
        /// <remarks>
        /// Do initialize the builder here. Use <see cref="OnPreBuild"/> instead.
        /// </remarks>
        protected override Recipe OnBuild()
        {
            return new Recipe(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
        }

        /// <summary>
        /// Is called after <see cref="OnBuild"/> to allow builders to initialize the subject's properties
        /// and fields that have not been initialized during constructor.
        /// </summary>
        protected override void OnPostBuild(Recipe subject)
        {
            subject.SetCamelCaseField(s => s.Ingredients, ingredients);
        }

        public RecipeBuilder WithRating(int rating)
        {
            return this;
        }

        public RecipeBuilder WithIngredient(float amount, Product product)
        {
            ingredients.Add(new Ingredient(amount, product));
            return this;
        }
    }
}